package leetcode.day_2020_12_21_12_28;

import leetcode.ListNode;

/**
 * 反转前链表n个结点
 */
public class Reverse_N {
    ListNode successor;
    ListNode reverseN(ListNode head, int n) {
        if(n == 1) {
            // 记录第n+1个结点；
            successor = head.next;
            return head;
        }
        // 以head.next为起点，需要反转前n-1个节点
        ListNode last = reverseN(head.next, n-1);
        head.next.next = head;
        head.next = successor;
        return last;
    }
}
